<template> 
    <div class="topics">
        <paste-page :list="TopicsPasteList"   @optBtn="optBtn"></paste-page>
        <div class="new-msg text-center" @click="jumpNewtopics"><i class="iconfont iconfont-jiajianzujianjiahao"></i></div>
    </div> 
</template>

<script> 
import * as api from '@/utils/api' 
import {ImgPath} from '@/utils/config' 
import pastePage from '@/components/paste-page' 
export default {
    onLoad(opt){ 
        this.getPasteList(opt.tId);
        this.tId=opt.tId
    },
    components: {
        pastePage, 
    }, 
    data () {
        return {
            TopicsPasteList:[],
            tId:'',
        }
    },
    methods:{
        getPasteList(id){
            let vm = this;
            let body={
                model: "Forums",
                with:{
                    "0":"topics",
                    "1":"collects",
                    "2":"shares",
                    "3":"comments"
                }, 
                limit:30, 
                condition: {
                    topic_id:id
                }
            };
            api.commonSite(body).then(res=>{
                if(res.data.code==200){
                    let imgArr=[];
                    res.data.data.data.forEach((item,index)=>{
                        if(item.images){
                            item.imgList=item.images.split(',');       
                        }
                    });
                    vm.TopicsPasteList=res.data.data.data;
                }
            })
        },
        optBtn(val,item){
            let vm = this;
            if(val=="collect"){ 
                let body={
                    model: "Records",
                    data:{
                        uid: wx.getStorageSync('u_id'),      
                        resource_id: item.forum_id,   
                        type:1,        
                        resource_type:7,   
                        category:"1" 
                    } 
                }; 
                if(item.is_collect==1){
                    api.deleteData(body).then(res=>{
                        if(res.data.code==200){
                            vm.getPasteList(this.tId);
                            wx.showToast({icon:'none', title: '取消成功' })
                        }
                    });
                }else{
                    api.createSite(body).then(res=>{
                        if(res.data.code==200){
                            vm.getPasteList(this.tId);
                            wx.showToast({icon:'none', title: '收藏成功' })
                        }
                    });
                }
            }
        },
        jumpNewtopics(){
            let url= `./../new-state/main?topicsId=${this.tId}`; 
            wx.navigateTo({url})  
        },
    }, 
}

</script>
<style scoped lang="scss">
.topics{
     .new-msg{
        position:fixed;
        bottom:100rpx; 
        right:20rpx;
        color:#CD4640;
        height:80rpx;
        line-height:80rpx;
        width:80rpx;
        border-radius:50%;
        border:1rpx solid #CD4640;
    }
}
</style> 
